<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="${pageContext.request.contextPath}/admin/scripts/jquery/jquery-1.7.1.js"></script>
<link href="${pageContext.request.contextPath}/admin/style/authority/basic_layout.css" rel="stylesheet" type="text/css">
<link href="${pageContext.request.contextPath}/admin/style/authority/common_style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="${pageContext.request.contextPath}/admin/scripts/authority/commonAll.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/admin/scripts/fancybox/jquery.fancybox-1.3.4.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/admin/scripts/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/admin/style/authority/jquery.fancybox-1.3.4.css" media="screen"></link>
<script type="text/javascript" src="${pageContext.request.contextPath}/admin/scripts/artDialog/artDialog.js?skin=default"></script>

<title></title>
<script type="text/javascript">

	/** 模糊查询  **/
	function search(){
		$("#submitForm").attr("action", "${pageContext.request.contextPath}/AdminProductServlet?method=findAllProductsWithPage&num=1").submit();
	}

	/** 新增   **/
	function add(){
		$("#submitForm").attr("action", "${pageContext.request.contextPath}/AdminProductServlet?method=addProductUI").submit();
	}
	/*删除*/
	 function del(pid){
		 $.ajax(
			 {
				 url:"${pageContext.request.contextPath}/AdminProductServlet?method=deleteProduct&pid="+pid,
				 method:'get',
				 success: function(data){
				 	//alert(data);
					if(data.flag =='true') {
						alert("删除成功")
						window.location.href="${pageContext.request.contextPath}/AdminProductServlet?method=findAllProductsWithPage&num=1"
					}else{
						alert("删除失败")
					}
				 },
				 error:function(err){
					 alert("删除失败");
				 }
			 });
	 }
</script>
<style>
	.alt td{ background:black !important;}
</style>
</head>
<body>
	<form id="submitForm" name="submitForm" action="" method="post">
		<div id="container">
			<div class="ui_content">
				<div class="ui_text_indent">
					<div id="box_border">
						<div id="box_top"  style="background: #9acfea">搜索</div>
						<div id="box_bottom">
                            <%--搜索选项--%>
								<select name="pflag" class="ui_input_txt02"  style="width:100px;height: 35px;">
									<option value="-1" <c:if test="${searchProduct.pflag == -1}">selected="selected"</c:if> >-请选择-</option>
									<option value="1" <c:if test="${searchProduct.pflag == 1}">selected="selected"</c:if> >下架</option>
									<option value="0" <c:if test="${searchProduct.pflag == 0}">selected="selected"</c:if> >在售</option>
								</select>
                            <select name="is_hot" class="ui_input_txt02"  style="width:100px;height: 35px;">
								<option value="-1" <c:if test="${searchProduct.is_hot == -1}">selected="selected"</c:if> >-请选择-</option>
								<option value="1" <c:if test="${searchProduct.is_hot == 1}">selected="selected"</c:if> >热门</option>
								<option value="0" <c:if test="${searchProduct.is_hot == 0}">selected="selected"</c:if> >不热门</option>
                            </select>
                            <select name="cid" class="ui_input_txt02" style="width:150px;height: 35px;">
								<option value="" <c:if test="${searchProduct.cid == null || searchProduct.cid == ''}">selected="selected"</c:if> >-请选择-</option>
                                <c:forEach items="${allCats}" var="c">
                                    <%--加载类目,设置搜索词对应的选择项--%>
                                    <option value="${c.cid}" <c:if test="${searchProduct.cid == c.cid}">selected="selected"</c:if> >${c.cname}</option>
                                </c:forEach>
                            </select>

							<input type="text" name="pname" value="${searchProduct.pname}" class="ui_input_txt02" style="width:120px;height: 35px;"/>
							<input type="button" value="查询" class="ui_input_btn01" onclick="search();" /> 
							<input type="button" value="新增" class="ui_input_btn01" onclick="add()" />
						</div>
					</div>
				</div>
			</div>
			<div class="ui_content">
				<div class="ui_tb">
					<table class="table" cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
						<tr>
							<th>序号</th>
							<th>商品图片</th>
							<th>商品名称</th>
							<th>商品价格</th>
							<th>是否热门</th>
							<th>是否下架</th>
							<th>操作</th>
						</tr>

						<c:forEach items="${page.list}" var="p" varStatus="status">
							<tr >
								<td >
										${ status.count+page.startIndex}
								</td>
								<td >
									<img width="40" height="45" src="${ pageContext.request.contextPath }/${p.pimage}">
								</td>
								<td>
										${ p.pname }
								</td>
								<td>
										${ p.shop_price }
								</td>
								<td>
									<c:if test="${p.is_hot == 1}">是</c:if>
									<c:if test="${p.is_hot == 0}">否</c:if>
								</td>
								<td>
									<c:if test="${p.pflag == 1}">下架</c:if>
									<c:if test="${p.pflag == 0}">在售</c:if>
								</td>

								<td>
									<a href="${pageContext.request.contextPath}/AdminProductServlet?method=findProductByPid&pid=${p.pid}" class="edit">编辑</a>
									<a href="javascript:del('${p.pid}');">删除</a>
								</td>
							</tr>
						</c:forEach>
						
					</table>
				</div>
				<div>
					<!--分页模块-->
					<%@ include file="/jsp/pageFile2.jsp" %>
				</div>
			</div>
		</div>
	</form>
</body>
</html>
